package pantallas;

import clases.Seccion;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/*
 * NewJFrame.java
 *
 * Created on 18 de febrero de 2011, 17:26
 */




public class Pantalla3 extends javax.swing.JFrame {
  private Seccion seccion;
  private boolean evaluacion; 
    public Pantalla3() {
        initComponents();
        seccion= new Seccion();
evaluacion=false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        jFrame2 = new javax.swing.JFrame();
        jFrame3 = new javax.swing.JFrame();
        jFrame4 = new javax.swing.JFrame();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jFrame2Layout = new javax.swing.GroupLayout(jFrame2.getContentPane());
        jFrame2.getContentPane().setLayout(jFrame2Layout);
        jFrame2Layout.setHorizontalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame2Layout.setVerticalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jFrame3Layout = new javax.swing.GroupLayout(jFrame3.getContentPane());
        jFrame3.getContentPane().setLayout(jFrame3Layout);
        jFrame3Layout.setHorizontalGroup(
            jFrame3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame3Layout.setVerticalGroup(
            jFrame3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jFrame4Layout = new javax.swing.GroupLayout(jFrame4.getContentPane());
        jFrame4.getContentPane().setLayout(jFrame4Layout);
        jFrame4Layout.setHorizontalGroup(
            jFrame4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame4Layout.setVerticalGroup(
            jFrame4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jInternalFrame1.setTitle("Menú");
        jInternalFrame1.setVisible(true);

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel6.setForeground(new java.awt.Color(0, 0, 255));
        jLabel6.setText("Opciones del Programa.");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(88, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addGap(75, 75, 75))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel6))
        );

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "1._Cargar Sección", "2._Inscribir Estudiante", "3._Retirar Estudiante", "4._Aplicar Evaluación.", "5._Listar por cedula", "6._Listar por Nota final", "7._Listar por Aplazados.", "8._Listar por Aprobados.", "9._Promedio de Nota." };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jList1MouseClicked(evt);
            }
        });
        jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jList1ValueChanged(evt);
            }
        });
        jList1.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jList1AncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        jScrollPane1.setViewportView(jList1);

        jButton1.setText("Salir.");
        jButton1.setAction(getAbstractAction1());

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addGap(181, 181, 181))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(27, 27, 27))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(186, 186, 186)
                        .addComponent(jButton1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1)))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(25, 25, 25))
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jInternalFrame1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jList1AncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jList1AncestorAdded
        // TODO add your handling code here:
       
    }//GEN-LAST:event_jList1AncestorAdded

    private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
        // TODO add your handling code here:

    }//GEN-LAST:event_jList1ValueChanged

    private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
        // TODO add your handling code here:
         String selecion = (String)jList1.getSelectedValue();
        System.out.println(selecion);
        if(selecion.equals("1._Cargar Sección")){
            Pantalla1 p = new Pantalla1();
            p.setSeccion(seccion);
            p.setVisible(true);
        }
        else if(selecion.equals("2._Inscribir Estudiante")){
            if(seccion.getNumseccion()!=-1){
                  Pantalla2 p = new Pantalla2();
                  p.setSeccion(seccion);
                  p.setVisible(true);
            }
            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);
        }
        else if(selecion.equals(" 3._Retirar Estudiante")){
             if(seccion.getNumseccion()!=-1)
                if(!seccion.getEstudiantes().isEmpty()){
                  Pantalla2 p = new Pantalla2();
                  p.setSeccion(seccion);
                  p.setVisible(true);
                }
                else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe inscribir al menos un estudiante","Principal",JOptionPane.WARNING_MESSAGE);

            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);

        }
        else if(selecion.equals("4._Aplicar Evaluación.")){
            if(seccion.getNumseccion()!=-1)
                if(!seccion.getEstudiantes().isEmpty())
                    if(seccion.getProf()!=null){
                        evaluacion=true;
                        seccion.getProf().aplicarEvaluacion(seccion.getEstudiantes());
                         JOptionPane.showMessageDialog(new JFrame(),"Los Estudiantes ya han presentado","Principal",JOptionPane.INFORMATION_MESSAGE);
                         JOptionPane.showMessageDialog(new JFrame(),"El Profesor ya he evaluado las notas","Principal",JOptionPane.INFORMATION_MESSAGE);

                    }
                    else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe asignar el profesor","Principal",JOptionPane.WARNING_MESSAGE);

                else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe inscribir al menos un estudiante","Principal",JOptionPane.WARNING_MESSAGE);

            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);

        }
        else if(selecion.equals("5._Listar por cedula")){
             if(seccion.getNumseccion()!=-1)
                if(!seccion.getEstudiantes().isEmpty()){
                        Pantalla4 p = new Pantalla4();
                        p.listarEstudiantes(seccion.ordenarCedula(), false);
                          p.setTitle("====LISTADO DE ESTUDIANTES POR DEDULA====");
                        p.setVisible(true);
                    }

                else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe inscribir al menos un estudiante","Principal",JOptionPane.WARNING_MESSAGE);

            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);

        }
        else if(selecion.equals("6._Listar por Nota final")){
               if(seccion.getNumseccion()!=-1)
                if(!seccion.getEstudiantes().isEmpty())
                    if(evaluacion){
                        Pantalla4 p = new Pantalla4();
                        p.listarEstudiantes(seccion.ordenarNota(), true);
                          p.setTitle("====LISTADO DE ESTUDIANTES POR NOTA FINAL====");
                        p.setVisible(true);
                    }
                    else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe aplicar las evaluaciones","Principal",JOptionPane.WARNING_MESSAGE);

                else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe inscribir al menos un estudiante","Principal",JOptionPane.WARNING_MESSAGE);

            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);

        }
        else if(selecion.equals("7._Listar por Aplazados.")){
               if(seccion.getNumseccion()!=-1)
                if(!seccion.getEstudiantes().isEmpty())
                    if(evaluacion){
                        Pantalla4 p = new Pantalla4();
                        p.listarEstudiantes(seccion.imprimirAplazados(), true);
                          p.setTitle("====LISTADO DE ESTUDIANTES REPROBADOS====");
                        p.setVisible(true);
                    }
                    else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe aplicar las evaluaciones","Principal",JOptionPane.WARNING_MESSAGE);

                else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe inscribir al menos un estudiante","Principal",JOptionPane.WARNING_MESSAGE);

            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);

        }
        else if(selecion.equals("8._Listar por Aprobados.")){
               if(seccion.getNumseccion()!=-1)
                if(!seccion.getEstudiantes().isEmpty())
                    if(evaluacion){
                        Pantalla4 p = new Pantalla4();
                        p.listarEstudiantes(seccion.imprimirAprobados(), true);
                        p.setTitle("====LISTADO DE ESTUDIANTES APROBADOS====");
                        p.setVisible(true);
                    }
                    else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe aplicar las evaluaciones","Principal",JOptionPane.WARNING_MESSAGE);

                else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe inscribir al menos un estudiante","Principal",JOptionPane.WARNING_MESSAGE);

            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);

        }
        else {
            if(seccion.getNumseccion()!=-1)
                if(!seccion.getEstudiantes().isEmpty())
                    if(evaluacion){
                        Pantalla1 p = new Pantalla1();
                        p.setSeccion(seccion);
                        p.mostrarPromedio();
                        p.setVisible(true);
                    }
                    else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe aplicar las evaluaciones","Principal",JOptionPane.WARNING_MESSAGE);

                else
                     JOptionPane.showMessageDialog(new JFrame(),"Debe inscribir al menos un estudiante","Principal",JOptionPane.WARNING_MESSAGE);

            else
                 JOptionPane.showMessageDialog(new JFrame(),"Debe crear la seccion","Principal",JOptionPane.WARNING_MESSAGE);

        }
    }//GEN-LAST:event_jList1MouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Pantalla3().setVisible(true);
            }
        });
    }
    
    private AbstractAction getAbstractAction1() {
    	if(abstractAction1 == null) {
    		abstractAction1 = new AbstractAction("Salir", null) {
    			public void actionPerformed(ActionEvent evt) {
    				dispose();
    			}
    		};
    	}
    	return abstractAction1;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JFrame jFrame2;
    private javax.swing.JFrame jFrame3;
    private javax.swing.JFrame jFrame4;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JList jList1;
    private AbstractAction abstractAction1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
